home *** CD-ROM | disk | FTP | other *** search
Korn shell script | 1995-03-24 | 1.8 KB | 79 lines |
- #! /bin/ksh
- USAGE='USAGE: duplicate_dir DIR_PATH MOUNT_PATH MAP_TO
- For every file in directory DIR_PATH, create a symbolic link to
- it by the same name in the current directory. If the link is
- below MOUNT_PATH, replace it with a linke with MOUNT_PATH
- replace by MAP_TO
- '
- # (C) Copyright 1995 by Michael Coulter. All rights reserved.
-
- # define std functions
-
- ISOFS_UTIL_DIR="${ISOFS_UTIL_DIR:-/usr/src/linux/fs/isofs/Utils}"
- . "$ISOFS_UTIL_DIR/ksh_fns"
-
-
- # Process parameters
-
- if [ $# -ne 3 ]
- then
- echo "$USAGE" >&2
- echo "3 arguments required. $# given." >&2
- exit 1
- fi
- if [ ! -d "$1" ]
- then
- echo "$1 is not a directory"
- fi
- DIR_ARG="$1"; shift
- if [ ! -d "$1" ]
- then
- echo "$1 is not a directory"
- fi
- MOUNT_PATH="$1"; shift
- if [ ! -d "$1" ]
- then
- echo "$1 is not a directory"
- fi
- MAP_TO="$1"; shift
-
- # Set DIR_PATH to hard path
-
- set -P # print absolut hw path
- HERE="$PWD"
- check_cmd 2 cd "$DIR_ARG"
- DIR_PATH="$PWD"
- check_cmd 3 cd "$HERE"
-
- # Do it
-
- PREFIX="${MAP_TO%/}/"
- (cd "$DIR_PATH"; ls -a -1) | while read FILE
- do
- if [ "$FILE" != '.' -a "$FILE" != '..' ]
- then
- DEST_FILE="$(follow_link "${DIR_PATH}/${FILE}")"
- if [ "$DEST_FILE" != "${DEST_FILE#${MOUNT_PATH}}" ]
- then
- # Use equivalent path
- DEST_FILE="${DEST_FILE#${MOUNT_PATH}/}"
- DEST_FILE="${PREFIX}$DEST_FILE"
- fi
- ## echo "HERE is $HERE"
- ## echo "DEST_FILE is $DEST_FILE"
- ## echo "FILE is $FILE"
- ## echo "PWD is $PWD"
- if [ "$DEST_FILE" = "$HERE/$FILE" ]
- then
- ln -s "$DIR_PATH/$FILE" "$FILE"
- else
- # Use relative path if possible
- ## echo "HERE is $HERE"
- ## echo "DEST_FILE is $DEST_FILE"
- DEST_FILE="${DEST_FILE#${HERE}/}"
- ## echo ln -s "$DEST_FILE" "${FILE}"
- ln -s "$DEST_FILE" "${FILE}"
- fi
- fi
- done
-